<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


</body>
<script>
  const arr = [1,3,5,7,9];
  let n1 = arr[0];
  let n2 = arr[1];
  let n3 = arr[2];
  let n4 = arr[3];
  let n5 = arr[4];

  /*数组解构赋值，变量名没有要求，顺序要和数组顺序保持一致*/
  let [no1,no2,no3,no4,no5] = arr;
  /*数组解构赋值，支持不完全解构*/
  let [num1,num2] = arr;
  /*数组的解构赋值，支持跳格解构,支持给默认值*/
  let [a1,,a3=300,,a5,a6=100] = arr;
  console.log(a1,a3,a5,a6)

  const obj = {
    name:"张三",
    age:10,
    sex:"男"
  }
  // let name = obj.name;
  // let age = obj.age;
  // let sex = obj.sex;
  /*对象的解构赋值，默认要求变量名和对象的属性名保持一致，对于顺序没有要求*/
  // let {name,age,sex} = obj;
  // console.log(age,name,sex)

  // let {sex} = obj;
  // console.log(sex);
  /*对象解构赋值，可以使用和对象属性不同的变量名进行接收*/
  let {name:xuqiang} = obj
  console.log(xuqiang);

  const test = {
    arr:[1,3,5]
  }
  let {arr:[,arr3]} = test;
  console.log(arr3);

  /*支持字符串解构赋值*/
  let [s1,s2,s3] = "hello world";
  console.log(s1,s2,s3);

  const json = {
    code:200,
    msg:"success"
  };

  function success(res) {
    if (res.code === 200) {
      // alert(res.msg);
      console.log(res.msg)
    }
  }
  success(json);

  function suc({ code, msg }) {
    if (code === 200) {
      console.log(msg)
    }
  }
  suc(json);


  let test1 = 100;
  let test2 = 200;
  console.log(test1);
  // let temp = test1;
  // test1 = test2;
  // test2 = temp;
  [test1,test2] = [test2,test1];
  console.log(test1,test2);
</script>
</html>